home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig02_26.jar / Ch02 / Fig02_26 / Fig02_26.cpp
C/C++ Source or Header  |  1997-10-11  |  404b  |  22 lines

  1. // Fig. 2.26: fig02_26.cpp
  2. // Using the break statement in a for structure
  3. #include <iostream.h>
  4.  
  5. int main()
  6. {
  7.    // x declared here so it can be used after the loop
  8.    int x; 
  9.  
  10.    for ( x = 1; x <= 10; x++ ) {
  11.  
  12.       if ( x == 5 )
  13.          break;    // break loop only if x is 5
  14.  
  15.       cout << x << " ";
  16.    }
  17.  
  18.    cout << "\nBroke out of loop at x of " << x << endl;
  19.    return 0;
  20. }
  21.  
  22.